package com.faeple.post.dao.sqlmap;

import java.util.HashMap;
import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.faeple.post.dao.PostDao;
import com.faeple.post.entity.CommentDto;
import com.faeple.post.entity.PostDto;

@Repository
public class SqlMapPostDao implements PostDao {

	@Autowired
	private SqlSession sqlSession;
	
	@Override
	public List<PostDto> loadPost(HashMap<String, String> map) {
		return sqlSession.selectList("PostMapper.loadPost", map);
	}

	@Override
	public int getLikeCount(String post_idx) {
		return sqlSession.selectOne("PostMapper.getLikeCount", post_idx);
	}

	@Override
	public int addLike(HashMap<String, String> map) {
		return sqlSession.insert("PostMapper.addLike", map);
	}

	@Override
	public int alreadyLike(HashMap<String, String> map) {
		return sqlSession.selectOne("PostMapper.alreadyLike",map);
	}

	@Override
	public List<CommentDto> getComment(String post_idx) {
		return sqlSession.selectList("PostMapper.getComment", post_idx);
	}

	@Override
	public int addComment(HashMap<String, String> map) {
		return sqlSession.insert("PostMapper.addComment", map);
	}

	@Override
	public int getCommentCnt(String post_idx) {
		return sqlSession.selectOne("PostMapper.getCommentCnt", post_idx);
	}

	@Override
	public int getShareCnt(String post_idx) {
		return sqlSession.selectOne("PostMapper.getShareCnt", post_idx);
	}

	@Override
	public int postWrite(HashMap<String, String> map) {
		return sqlSession.insert("PostMapper.postWrite", map);
	}

	@Override
	public void imageUpload(HashMap<String, String> map) {
		sqlSession.insert("PostMapper.imageUpload", map);
	}

	@Override
	public HashMap<String, Object> getPostImage(String image) {
		return sqlSession.selectOne("PostMapper.getPostImage", image);
	}

	@Override
	public int checkUrl(String url) {
		return sqlSession.selectOne("PostMapper.checkUrl", url);
	}

	@Override
	public PostDto getPostWithUrl(String url) {
		return sqlSession.selectOne("PostMapper.getPostWithUrl", url);
	}

	@Override
	public List<CommentDto> getCommentWithPost(HashMap<String, String> map) {
		return sqlSession.selectList("PostMapper.getCommentWithPost", map);
	}

	@Override
	public int alreadyCommentLike(HashMap<String, String> map) {
		return sqlSession.selectOne("PostMapper.alreadyCommentLike", map);
	}

	@Override
	public int commentLike(HashMap<String, String> map) {
		sqlSession.update("PostMapper.commentLikeCntAdd", map);
		return sqlSession.insert("PostMapper.commentLike", map);
	}

	@Override
	public int getCommentLikeCount(String comment_idx) {
		return sqlSession.selectOne("PostMapper.getCommentLikeCount", comment_idx);
	}

	@Override
	public List<String> getCommentLikeNames(String comment_idx) {
		return sqlSession.selectList("PostMapper.getCommentLikeNames", comment_idx);
	}

	@Override
	public int checkCommentAuthor(String comment_idx) {
		return sqlSession.selectOne("PostMapper.checkCommentAuthor", comment_idx);
	}

	@Override
	public int deleteComment(String comment_idx) {
		return sqlSession.delete("PostMapper.deleteComment", comment_idx);
	}

	@Override
	public int updateComment(HashMap<String, String> map) {
		return sqlSession.update("PostMapper.updateComment", map);
	}

	@Override
	public int alreadyPosthistory(HashMap<String, String> map) {
		return sqlSession.selectOne("PostMapper.alreadyPosthistory", map);
	}

	@Override
	public int addPosthistory(HashMap<String, String> map) {
		return sqlSession.insert("PostMapper.addPosthistory", map);
	}

	@Override
	public List<HashMap<String, String>> getPostLikeMemberList(HashMap<String, String> map) {
		return sqlSession.selectList("PostMapper.getPostLikeMemberList", map);
	}

	@Override
	public int addTag(HashMap<String, Object> tags) {
		return sqlSession.insert("PostMapper.addTag", tags);
	}

	@Override
	public List<String> getTag(String post_idx) {
		return sqlSession.selectList("PostMapper.getTag", post_idx);
	}

	@Override
	public int unLike(HashMap<String, String> map) {
		return sqlSession.delete("PostMapper.unLike", map);
	}

	@Override
	public List<PostDto> getPostWithTag(HashMap<String, String> param) {
		return sqlSession.selectList("PostMapper.getPostWithTag", param);
	}

	@Override
	public int getTagCount(String tag) {
		return sqlSession.selectOne("PostMapper.getTagCount", tag);
	}

	@Override
	public List<PostDto> getHomeFeed(HashMap<String, Object> param) {
		return sqlSession.selectList("PostMapper.getHomeFeed", param);
	}

	@Override
	public int getCategoryResultCount(HashMap<String, String> map) {
		return sqlSession.selectOne("PostMapper.getCategoryResultCount", map);
	}

	@Override
	public List<PostDto> loadCategoryPost(HashMap<String, String> map) {
		return sqlSession.selectList("PostMapper.loadCategoryPost", map);
	}

	@Override
	public int deletePost(HashMap<String, String> param){
		return sqlSession.delete("PostMapper.deletePost", param);
	}

	@Override
	public PostDto getPostInfo(String idx) {
		return sqlSession.selectOne("PostMapper.getPostInfo", idx);
	}

	@Override
	public int updatePost(HashMap<String, String> param) {
		return sqlSession.update("PostMapper.updatePost", param);
	}

	@Override
	public int deleteTag(String post_idx) {
		return sqlSession.delete("PostMapper.deleteTag",post_idx);
	}

	@Override
	public List<PostDto> loadColorPost(HashMap<String, String> map) {
		return sqlSession.selectList("PostMapper.loadColorPost", map);
	}

	@Override
	public int getColorResultCount(HashMap<String, String> param) {
		return sqlSession.selectOne("PostMapper.getColorResultCount", param);
	}

	@Override
	public List<HashMap<String, String>> getRecommendedTags() {
		return sqlSession.selectList("PostMapper.getRecommendedTags");
	}

	@Override
	public int setPostViewCnt(HashMap<String, String> param) {
		return sqlSession.insert("PostMapper.setPostViewCnt", param);
	}

	@Override
	public void addPostViewCnt(String idx) {
		sqlSession.update("PostMapper.addPostViewCnt", idx);
	}

	@Override
	public int addPostViewStats(HashMap<String, String> param) {
		return sqlSession.insert("PostMapper.addPostViewStats", param);
	}

	@Override
	public List<HashMap<String, String>>getHashTagList(HashMap<String, String> param) {
		return sqlSession.selectList("PostMapper.getHashTagList", param);
	}

}
